home *** CD-ROM | disk | FTP | other *** search
/ PD Collection CD 1 / PD Collection CD 1.iso / textual / gnudiff / C / Io < prev    next >
Text File  |  1991-09-29  |  19KB  |  649 lines

  1. /* File I/O for GNU DIFF.
  2.    Copyright (C) 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU DIFF.
  5.  
  6. GNU DIFF is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU DIFF is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU DIFF; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "diff.h"
  21.  
  22. static int binary_file_p (char *, int);
  23. static int slurp (void);
  24. static void find_identical_ends (struct file_data *);
  25. static int find_equiv_class (int);
  26.  
  27. /* Rotate a value n bits to the left. */
  28. #define UINT_BIT (sizeof (unsigned) * CHAR_BIT)
  29. #define ROL(v, n) ((v) << (n) | (v) >> UINT_BIT - (n))
  30.  
  31. /* Given a hash value and a new character, return a new hash value. */
  32. #define HASH(h, c) ((c) + ROL (h, 7))
  33.  
  34. /* Current file under consideration. */
  35. struct file_data *current;
  36.  
  37. /* Check for binary files and compare them for exact identity.  */
  38.  
  39. /* Return 1 if BUF contains a non text character.
  40.    SIZE is the number of characters in BUF.  */
  41.  
  42. static int binary_file_p (char *buf, int size)
  43. {
  44.   static const char textchar[] = {
  45.     /* ISO 8859 */
  46.     0, 0, 0, 0, 0, 0, 0, 0,
  47.     0, 1, 1, 1, 1, 1, 0, 0,
  48.     0, 0, 0, 0, 0, 0, 0, 0,
  49.     0, 0, 0, 0, 0, 0, 0, 0,
  50.     1, 1, 1, 1, 1, 1, 1, 1,
  51.     1, 1, 1, 1, 1, 1, 1, 1,
  52.     1, 1, 1, 1, 1, 1, 1, 1,
  53.     1, 1, 1, 1, 1, 1, 1, 1,
  54.     1, 1, 1, 1, 1, 1, 1, 1,
  55.     1, 1, 1, 1, 1, 1, 1, 1,
  56.     1, 1, 1, 1, 1, 1, 1, 1,
  57.     1, 1, 1, 1, 1, 1, 1, 1,
  58.     1, 1, 1, 1, 1, 1, 1, 1,
  59.     1, 1, 1, 1, 1, 1, 1, 1,
  60.     1, 1, 1, 1, 1, 1, 1, 1,
  61.     1, 1, 1, 1, 1, 1, 1, 0,
  62.     0, 0, 0, 0, 0, 0, 0, 0,
  63.     0, 0, 0, 0, 0, 0, 0, 0,
  64.     0, 0, 0, 0, 0, 0, 0, 0,
  65.     0, 0, 0, 0, 0, 0, 0, 0,
  66.     1, 1, 1, 1, 1, 1, 1, 1,
  67.     1, 1, 1, 1, 1, 1, 1, 1,
  68.     1, 1, 1, 1, 1, 1, 1, 1,
  69.     1, 1, 1, 1, 1, 1, 1, 1,
  70.     1, 1, 1, 1, 1, 1, 1, 1,
  71.     1, 1, 1, 1, 1, 1, 1, 1,
  72.     1, 1, 1, 1, 1, 1, 1, 1,
  73.     1, 1, 1, 1, 1, 1, 1, 1,
  74.     1, 1, 1, 1, 1, 1, 1, 1,
  75.     1, 1, 1, 1, 1, 1, 1, 1,
  76.     1, 1, 1, 1, 1, 1, 1, 1,
  77.     1, 1, 1, 1, 1, 1, 1, 1,
  78.   };
  79.   while (--size >= 0)
  80.     if (!textchar[*buf++ & 0377])
  81.       return 1;
  82.   return 0;
  83. }
  84.  
  85. int binary_file_threshold = 512;
  86.  
  87. /* Slurp the current file completely into core.
  88.    Return nonzero if it appears to be a binary file.  */
  89.  
  90. static int slurp (void)
  91. {
  92.   /* If we have a nonexistent file at this stage, treat it as empty.  */
  93.   if (current->desc < 0)
  94.     {
  95.       current->bufsize = 0;
  96.       current->buffered_chars = 0;
  97.       current->buffer = 0;
  98.     }
  99.   /* If it's a regular file, we can just get the size out of the stat
  100.      block and slurp it in all at once. */
  101.   /* In all cases, we leave room in the buffer for 2 extra chars
  102.      beyond those that current->bufsize describes:
  103.      one for a newline (in case the text does not end with one)
  104.      and one for a sentinel in find_identical_ends.  */
  105.   else if (current->desc > 0)
  106.     {
  107.       _kernel_osgbpb_block blk;
  108.  
  109.       current->bufsize = current->length;
  110.       current->buffer = (char *) xmalloc (current->bufsize + 2);
  111.  
  112.       blk.dataptr = current->buffer;
  113.       blk.nbytes = current->length;
  114.       blk.fileptr = 0;
  115.       if (_kernel_osgbpb (3, current->desc, &blk) == _kernel_ERROR)
  116.     {
  117.       _kernel_oserror *err = _kernel_last_oserror();
  118.       fprintf(stderr, "%s: Cannot read %s (Error %d - %s)\n",
  119.           program, current->name, err->errnum, err->errmess);
  120.       exit (2);
  121.     }
  122.       else if (blk.nbytes != 0)
  123.     {
  124.       fprintf(stderr, "%s: Cannot read all of %s\n", program, current->name);
  125.       exit (2);
  126.     }
  127.  
  128.       current->buffered_chars = current->length;
  129.     }
  130.   else
  131.     {
  132.       int cc;
  133.  
  134.       current->bufsize = 4096;
  135.       current->buffer = (char *) xmalloc (current->bufsize + 2);
  136.       current->buffered_chars = 0;
  137.       
  138.       /* Standard input - Read it in a little at a time, growing the
  139.      buffer as necessary. */
  140.       while (!feof(stdin) && !ferror(stdin))
  141.     {
  142.       cc = fread (current->buffer + current->buffered_chars, 1,
  143.               current->bufsize - current->buffered_chars, stdin);
  144.       current->buffered_chars += cc;
  145.       if (current->buffered_chars == current->bufsize)
  146.         {
  147.           current->bufsize = current->bufsize * 2;
  148.           current->buffer = (char *) xrealloc (current->buffer,
  149.                            current->bufsize + 2);
  150.         }
  151.     }
  152.       if (ferror(stdin))
  153.     {
  154.       fprintf(stderr, "%s: Cannot read all of %s\n",
  155.           program, current->name);
  156.       exit (2);
  157.     }
  158.     }
  159.  
  160.   /* Check first part of file to see if it's a binary file.  */
  161.   if (! always_text_flag
  162.       && binary_file_p (current->buffer,
  163.             min (current->buffered_chars, binary_file_threshold)))
  164.     return 1;
  165.  
  166.   /* If not binary, make sure text ends in a newline,
  167.      but remember that we had to add one unless -B is in effect.  */
  168.   if (current->buffered_chars > 0
  169.       && current->buffer[current->buffered_chars - 1] != '\n')
  170.     {
  171.       current->missing_newline = !ignore_blank_lines_flag;
  172.       current->buffer[current->buffered_chars++] = '\n';
  173.     }
  174.   else
  175.     current->missing_newline = 0;
  176.  
  177.   /* Don't use uninitialized storage. */
  178.   if (current->buffer != 0)
  179.     current->buffer[current->buffered_chars] = '\0';
  180.  
  181.   return 0;
  182. }
  183.  
  184. /* Split the file into lines, simultaneously computing the hash codes for
  185.    each line. */
  186.  
  187. void find_and_hash_each_line (void)
  188. {
  189.   unsigned h;
  190.   int i;
  191.   unsigned char *p = (unsigned char *) current->prefix_end, *ip, c;
  192.  
  193.   /* Attempt to get a good initial guess as to the number of lines. */
  194.   current->linbufsize = current->buffered_chars / 50 + 5;
  195.   current->linbuf
  196.     = (struct line_def *) xmalloc (current->linbufsize * sizeof (struct line_def));
  197.  
  198.   if (function_regexp || output_style == OUTPUT_IFDEF)
  199.     {
  200.       /* If the -C, -D or -F option is used, we need to find the lines
  201.      of the matching prefix.  At least we will need to find the last few,
  202.      but since we don't know how many, it's easiest to find them all.
  203.      If -D is specified, we need all the lines of the first file.  */
  204.       current->buffered_lines = 0;
  205.       p = (unsigned char *) current->buffer;
  206.     }
  207.   else
  208.     {
  209.       /* Skip the identical prefixes, except be prepared to handle context.
  210.      In fact, handle 1 more preceding line than the context says,
  211.      in case shift_boundaries moves things backwards in this file.  */
  212.       current->buffered_lines = current->prefix_lines - context - 1;
  213.       if (current->buffered_lines < 0)
  214.     current->buffered_lines = 0;
  215.       for (i = 0; i < context + 1; ++i)
  216.     /* Unless we are at the beginning, */
  217.     if ((char *) p != current->buffer)
  218.       /* Back up at least 1 char until at the start of a line.  */
  219.       while ((char *) --p != current->buffer && p[-1] != '\n')
  220.         ;
  221.     }
  222.  
  223.   while ((char *) p < current->suffix_begin)
  224.     {
  225.       h = 0;
  226.       ip = p;
  227.  
  228.       if (current->prefix_end <= (char *) p)
  229.     {
  230.       /* Hash this line until we find a newline. */
  231.       if (ignore_case_flag)
  232.         {
  233.           if (ignore_all_space_flag)
  234.         while ((c = *p) != '\n')
  235.           {
  236.             if (! isspace (c))
  237.               {
  238.             if (isupper (c))
  239.               h = HASH (h, tolower (c));
  240.             else
  241.               h = HASH (h, c);
  242.               }
  243.             ++p;
  244.           }
  245.           else if (ignore_space_change_flag)
  246.  
  247.         while ((c = *p) != '\n')
  248.           {
  249.             if (c == ' ' || c == '\t')
  250.               {
  251.             while ((c = *p) == ' ' || c == '\t')
  252.               ++p;
  253.             if (c == '\n')
  254.               break;
  255.             h = HASH (h, ' ');
  256.               }
  257.             /* C is now the first non-space.  */
  258.             if (isupper (c))
  259.               h = HASH (h, tolower (c));
  260.             else
  261.               h = HASH (h, c);
  262.             ++p;
  263.           }
  264.           else
  265.         while ((c = *p) != '\n')
  266.           {
  267.             if (isupper (c))
  268.               h = HASH (h, tolower (c));
  269.             else
  270.               h = HASH (h, c);
  271.             ++p;
  272.           }
  273.         }
  274.       else
  275.         {
  276.           if (ignore_all_space_flag)
  277.         while ((c = *p) != '\n')
  278.           {
  279.             if (! isspace (c))
  280.               h = HASH (h, c);
  281.             ++p;
  282.           }
  283.           else if (ignore_space_change_flag)
  284.         while ((c = *p) != '\n')
  285.           {
  286.             if (c == ' ' || c == '\t')
  287.               {
  288.             while ((c = *p) == ' ' || c == '\t')
  289.               ++p;
  290.             if (c == '\n')
  291.               break;
  292.             h = HASH (h, ' ');
  293.               }
  294.             /* C is not the first non-space.  */
  295.             h = HASH (h, c);
  296.             ++p;
  297.           }
  298.           else
  299.         while ((c = *p) != '\n')
  300.           {
  301.             h = HASH (h, c);
  302.             ++p;
  303.           }
  304.         }
  305.     }
  306.       else
  307.     /* This line is part of the matching prefix,
  308.        so we don't need to hash it.  */
  309.     while (*p != '\n')
  310.       ++p;
  311.       
  312.       /* Maybe increase the size of the line table. */
  313.       if (current->buffered_lines >= current->linbufsize)
  314.     {
  315.       while (current->buffered_lines >= current->linbufsize)
  316.         current->linbufsize *= 2;
  317.       current->linbuf
  318.         = (struct line_def *) xrealloc (current->linbuf,
  319.                         current->linbufsize
  320.                         * sizeof (struct line_def));
  321.     }
  322.       current->linbuf[current->buffered_lines].text = (char *) ip;
  323.       current->linbuf[current->buffered_lines].length = p - ip + 1;
  324.       current->linbuf[current->buffered_lines].hash = h;
  325.       ++current->buffered_lines;
  326.       ++p;
  327.     }
  328.  
  329.   i = 0;
  330.   while ((i < context || output_style == OUTPUT_IFDEF)
  331.      && (char *) p < current->buffer + current->buffered_chars)
  332.     {
  333.       ip = p;
  334.       while (*p++ != '\n')
  335.     ;
  336.       /* Maybe increase the size of the line table. */
  337.       if (current->buffered_lines >= current->linbufsize)
  338.     {
  339.       while (current->buffered_lines >= current->linbufsize)
  340.         current->linbufsize *= 2;
  341.       current->linbuf
  342.         = (struct line_def *) xrealloc (current->linbuf,
  343.                         current->linbufsize
  344.                         * sizeof (struct line_def));
  345.     }
  346.       current->linbuf[current->buffered_lines].text = (char *) ip;
  347.       current->linbuf[current->buffered_lines].length = p - ip;
  348.       current->linbuf[current->buffered_lines].hash = 0;
  349.       ++current->buffered_lines;
  350.       ++i;
  351.     }
  352.  
  353.   if (ROBUST_OUTPUT_STYLE (output_style)
  354.       && current->missing_newline
  355.       && current->suffix_begin == current->buffer + current->buffered_chars)
  356.     --current->linbuf[current->buffered_lines - 1].length;
  357. }
  358.  
  359. /* Given a vector of two file_data objects, find the identical
  360.    prefixes and suffixes of each object. */
  361.  
  362. static void find_identical_ends (struct file_data *filevec)
  363. {
  364.   char *p0, *p1, *end0, *beg0;
  365.   int lines;
  366.  
  367.   if (filevec[0].buffered_chars == 0 || filevec[1].buffered_chars == 0)
  368.     {
  369.       filevec[0].prefix_end = filevec[0].buffer;
  370.       filevec[1].prefix_end = filevec[1].buffer;
  371.       filevec[0].prefix_lines = filevec[1].prefix_lines = 0;
  372.       filevec[0].suffix_begin = filevec[0].buffer + filevec[0].buffered_chars;
  373.       filevec[1].suffix_begin = filevec[1].buffer + filevec[1].buffered_chars;
  374.       filevec[0].suffix_lines = filevec[1].suffix_lines = 0;
  375.       return;
  376.     }
  377.  
  378.   /* Find identical prefix.  */
  379.  
  380.   p0 = filevec[0].buffer;
  381.   p1 = filevec[1].buffer;
  382.   lines = 0;
  383.  
  384.   /* Insert end "sentinels", in this case characters that are guaranteed
  385.      to make the equality test false, and thus terminate the loop.  */
  386.  
  387.   if (filevec[0].buffered_chars < filevec[1].buffered_chars)
  388.     p0[filevec[0].buffered_chars] = ~p1[filevec[0].buffered_chars];
  389.   else
  390.     p1[filevec[1].buffered_chars] = ~p0[filevec[1].buffered_chars];
  391.  
  392.   /* Loop until first mismatch, or to the sentinel characters.  */
  393.   while (1)
  394.     {
  395.       char c = *p0++;
  396.       if (c != *p1++)
  397.     break;
  398.       if (c == '\n')
  399.     ++lines;
  400.     }
  401.  
  402.   /* Don't count missing newline as part of prefix in RCS mode. */
  403.   if (ROBUST_OUTPUT_STYLE (output_style)
  404.       && ((filevec[0].missing_newline
  405.        && p0 - filevec[0].buffer > filevec[0].buffered_chars)
  406.       ||
  407.       (filevec[1].missing_newline
  408.        && p1 - filevec[1].buffer > filevec[1].buffered_chars)))
  409.     --p0, --p1, --lines;
  410.  
  411.   /* If the sentinel was passed, and lengths are equal, the
  412.      files are identical.  */
  413.   if (p0 - filevec[0].buffer > filevec[0].buffered_chars
  414.       && filevec[0].buffered_chars == filevec[1].buffered_chars)
  415.     {
  416.       filevec[0].prefix_end = p0 - 1;
  417.       filevec[1].prefix_end = p1 - 1;
  418.       filevec[0].prefix_lines = filevec[1].prefix_lines = lines;
  419.       filevec[0].suffix_begin = filevec[0].buffer;
  420.       filevec[1].suffix_begin = filevec[1].buffer;
  421.       filevec[0].suffix_lines = filevec[1].suffix_lines = lines;
  422.       return;
  423.     }
  424.  
  425.   /* Point at first nonmatching characters.  */
  426.   --p0, --p1;
  427.  
  428.   /* Skip back to last line-beginning in the prefix.  */
  429.   while (p0 != filevec[0].buffer && p0[-1] != '\n')
  430.     --p0, --p1;
  431.  
  432.   /* Record the prefix.  */
  433.   filevec[0].prefix_end = p0;
  434.   filevec[1].prefix_end = p1;
  435.   filevec[0].prefix_lines = filevec[1].prefix_lines = lines;
  436.   
  437.   /* Find identical suffix.  */
  438.  
  439.   /* P0 and P1 point beyond the last chars not yet compared.  */
  440.   p0 = filevec[0].buffer + filevec[0].buffered_chars;
  441.   p1 = filevec[1].buffer + filevec[1].buffered_chars;
  442.   lines = 0;
  443.  
  444.   if (! ROBUST_OUTPUT_STYLE (output_style)
  445.       || filevec[0].missing_newline == filevec[1].missing_newline)
  446.     {
  447.       end0 = p0;        /* Addr of last char in file 0.  */
  448.  
  449.       /* Get value of P0 at which we should stop scanning backward:
  450.      this is when either P0 or P1 points just past the last char
  451.      of the identical prefix.  */
  452.       if (filevec[0].buffered_chars < filevec[1].buffered_chars)
  453.     beg0 = filevec[0].prefix_end;
  454.       else
  455.     /* Figure out where P0 will be when P1 is at the end of the prefix.
  456.        Thus we only need to test P0.  */
  457.     beg0 = (filevec[0].prefix_end
  458.         + filevec[0].buffered_chars - filevec[1].buffered_chars);
  459.  
  460.       /* Scan back until chars don't match or we reach that point.  */
  461.       while (p0 != beg0)
  462.     {
  463.       char c = *--p0;
  464.       if (c != *--p1)
  465.         {
  466.           /* Point at the first char of the matching suffix.  */
  467.           ++p0, ++p1;
  468.           break;
  469.         }
  470.       if (c == '\n')
  471.         ++lines;
  472.     }
  473.  
  474.       /* Are we at a line-beginning in both files?  */
  475.       if (p0 != end0
  476.       && !((p0 == filevec[0].buffer || p0[-1] == '\n')
  477.            &&
  478.            (p1 == filevec[1].buffer || p1[-1] == '\n')))
  479.     {
  480.       /* No.  We counted one line too many.  */
  481.       --lines;
  482.       /* Advance to next place that is a line-beginning in both files.  */
  483.       do
  484.         {
  485.           ++p0, ++p1;
  486.         }
  487.       while (p0 != end0 && p0[-1] != '\n');
  488.     }
  489.     }
  490.  
  491.   /* Record the suffix.  */
  492.   filevec[0].suffix_begin = p0;
  493.   filevec[1].suffix_begin = p1;
  494.   filevec[0].suffix_lines = filevec[1].suffix_lines = lines;
  495. }
  496.  
  497. /* Lines are put into equivalence classes (of lines that match in line_cmp).
  498.    Each equivalence class is represented by one of these structures,
  499.    but only while the classes are being computed.
  500.    Afterward, each class is represented by a number.  */
  501. struct equivclass
  502. {
  503.   struct equivclass *next;    /* Next item in this bucket. */
  504.   struct line_def line;    /* A line that fits this class. */
  505. };
  506.  
  507. /* Hash-table: array of buckets, each being a chain of equivalence classes.  */
  508. static struct equivclass **buckets;
  509.   
  510. /* Size of the bucket array. */
  511. static int nbuckets;
  512.  
  513. /* Array in which the equivalence classes are allocated.
  514.    The bucket-chains go through the elements in this array.
  515.    The number of an equivalence class is its index in this array.  */
  516. static struct equivclass *equivs;
  517.  
  518. /* Index of first free element in the array `equivs'.  */
  519. static int equivs_index;
  520.  
  521. /* Size allocated to the array `equivs'.  */
  522. static int equivs_alloc;
  523.  
  524. /* Largest primes less than some power of two, for nbuckets.  Values range
  525.    from useful to preposterous.  If one of these numbers isn't prime
  526.    after all, don't blame it on me, blame it on primes (6) . . . */
  527. static int primes[] =
  528. {
  529.   509,
  530.   1021,
  531.   2039,
  532.   4093,
  533.   8191,
  534.   16381,
  535.   32749,
  536.   65521,
  537.   131071,
  538.   262139,
  539.   524287,
  540.   1048573,
  541.   2097143,
  542.   4194301,
  543.   8388593,
  544.   16777213,
  545.   33554393,
  546.   67108859,            /* Preposterously large . . . */
  547.   -1
  548. };
  549.  
  550. /* Index of current nbuckets in primes. */
  551. static int primes_index;
  552.  
  553. /* Find the equiv class associated with line N of the current file.  */
  554.  
  555. static int find_equiv_class (int n)
  556. {
  557.   int bucket;
  558.   struct equivclass *b, *p = NULL;
  559.  
  560.   /* Equivalence class 0 is permanently allocated to lines that were
  561.      not hashed because they were parts of identical prefixes or
  562.      suffixes. */
  563.   if (n < current->prefix_lines
  564.       || current->linbuf[n].text >= current->suffix_begin)
  565.     return 0;
  566.  
  567.   /* Check through the appropriate bucket to see if there isn't already
  568.      an equivalence class for this line. */
  569.   bucket = (current->linbuf[n].hash & 0x7FFFFFFF) % nbuckets;
  570.   b = buckets[bucket];
  571.   while (b)
  572.     {
  573.       if (b->line.hash == current->linbuf[n].hash
  574.       && (b->line.length == current->linbuf[n].length
  575.           /* Lines of different lengths can match with certain options.  */
  576.           || length_varies)
  577.       && !line_cmp (&b->line, ¤t->linbuf[n]))
  578.     return b - equivs;
  579.       p = b, b = b->next;
  580.     }
  581.  
  582.   /* Create a new equivalence class in this bucket. */
  583.  
  584.   p = &equivs[equivs_index++];
  585.   p->next = buckets[bucket];
  586.   buckets[bucket] = p;
  587.   p->line = current->linbuf[n];
  588.  
  589.   return equivs_index - 1;
  590. }
  591.  
  592. /* Given a vector of two file_data objects, read the file associated
  593.    with each one, and build the table of equivalence classes.
  594.    Return nonzero if either file appears to be a binary file.  */
  595.  
  596. int read_files (struct file_data *filevec)
  597. {
  598.   int i, j;
  599.   int binary = 0;
  600.   int this_binary;
  601.  
  602.   current = &filevec[0];
  603.   binary = this_binary = slurp ();
  604.  
  605.   current = &filevec[1];
  606.   this_binary = slurp ();
  607.   if (binary || this_binary)
  608.     return 1;
  609.  
  610.   find_identical_ends (filevec);
  611.  
  612.   for (i = 0; i < 2; ++i)
  613.     {
  614.       current = &filevec[i];
  615.       find_and_hash_each_line ();
  616.     }
  617.  
  618.   /* This is guaranteed to be enough space.  */
  619.   equivs_alloc = filevec[0].buffered_lines + filevec[1].buffered_lines + 1;
  620.   equivs = (struct equivclass *) xmalloc (equivs_alloc * sizeof (struct equivclass));
  621.   /* Equivalence class 0 is permanently safe for lines that were not
  622.      hashed.  Real equivalence classes start at 1. */
  623.   equivs_index = 1;
  624.   
  625.   primes_index = 0;
  626.   while (primes[primes_index] < equivs_alloc / 3)
  627.     primes_index++;
  628.  
  629.   buckets = (struct equivclass **) xmalloc (primes[primes_index] * sizeof (struct equivclass *));
  630.   bzero (buckets, primes[primes_index] * sizeof (struct equivclass *));
  631.   nbuckets = primes[primes_index];
  632.  
  633.   for (i = 0; i < 2; ++i)
  634.     {
  635.       current = &filevec[i];
  636.       current->equivs
  637.     = (int *) xmalloc (current->buffered_lines * sizeof (int));
  638.       for (j = 0; j < current->buffered_lines; ++j)
  639.     current->equivs[j] = find_equiv_class (j);
  640.     }
  641.  
  642.   filevec[0].equiv_max = filevec[1].equiv_max = equivs_index;
  643.  
  644.   free (equivs);
  645.   free (buckets);
  646.  
  647.   return 0;
  648. }
  649.